package com.generic.demo2;


/**
 * @ClassName 泛型类
 * @Description 实例化某个类的对象
 * @Author Kx
 * @Date 2025/3/26 10:51
 * @Version 1.0
 */
public class GenericIty<T> {
    private final Class<T> type;

    public GenericIty(Class<T> type) {
        this.type = type;
    }

    /***
     * @author: kx
     * @date: 2025/3/26 11:04
     * @return T 返回的实例
     * @description: 获取某个类的对象的方法
    */
    public T create() {
        try {
            return type.getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            throw new RuntimeException("无法创建" + type.getName() + "实例");
        }
    }
}
